<template>
	<view :data-theme="themeStyle" class="allPage" :class="{ bottom: hasData }">
		<view class="cart-header fixed" v-if="cartData.length">
			<view class="num-wrap font-size-toolbar">
				<text class="sextraction">自提点：{{membercommunity}}</text>
			</view>
			<view class="cart-action" @click="changeAction">{{ isAction ? $lang('complete') : $lang('edit') }}</view>
		</view>
		<scroll-view class="container" :scroll-x="true" :show-scrollbar="false">
			<block v-if="hasData">
				<view class="cart-wrap" v-for="(siteItem, siteIndex) in cartData" :key="siteIndex">
					<view class="fixed-wrap"></view>
					<block v-for="(item, cartIndex) in siteItem.cartList" :key="cartIndex">

						<view class="cart-goods" @touchstart="touchS($event)" @touchend="touchE($event, item)">
							<view class="shop-sk-head" v-if="item.activity_type == 'seckill'">
								<text class="mr-10">距离活动结束</text>
								<uni-count-down :hour="item.discountTimeMachine.h" :minute="item.discountTimeMachine.i"
									:second="item.discountTimeMachine.s" color="#fff" splitorColor="#303133"
									backgroundColor="#303133" />
								<view class="sec-kill-shop">{{item.activity_tag}}</view>
							</view>
							<view class="goods-wrap" :class="{ edit: item.edit }">
								<view class="iconfont"
									:class="item.checked ? 'iconyuan_checked color-import color-base-text' : 'iconyuan_checkbox'"
									@click="singleElection(siteIndex, cartIndex)"></view>
								<view @click="toGoodsDetail(item)" class="goods-img">
									<image :src="$util.img(item.sku_image, { size: 'mid' })"
										@error="imageError(siteIndex, cartIndex)" mode="aspectFill"></image>
								</view>
								<view class="goods-info">
									<view @click="toGoodsDetail(item)" class="goods-name">{{ item.goods_name }}</view>
									<view class="sku">
										<view class="goods-spec">
											<text>{{$util.timeStampTurnTime( communityConfig, '' ,1 ).slice(5,16)}} 可提货</text>
											<text v-if="item.activity_max_buy ">限购{{item.activity_max_buy}}件</text>
										</view>
									</view>
									<view class="goods-sub-section">
										<view>
											<view class="goods-price color-base-text">
												<view class="bottom-price">
													<text class="unit">{{ $lang('common.currencySymbol') }}</text>
													<text v-if="item.activity_type === 'seckill'"><text
															class="fs-38">{{ item.activity_price.split('.')[0] }}</text>.{{item.activity_price.split('.')[1]}}</text>
													<text v-else><text
															class="fs-38">{{ item.discount_price.split('.')[0] }}</text>.{{item.discount_price.split('.')[1]}}</text>
												</view>
											</view>
											<view class="goods-notes-text">
												<text class="unit">{{ $lang('common.currencySymbol') }}</text>
												<text> {{item.market_price > 0 ? item.market_price : item.price}} </text>
											</view>
										</view>
										<uni-number-box :min="item.min_buy > 1 ? item.min_buy : 1"
											:max="item.max_buy > 0 && item.max_buy < item.stock ? item.max_buy : item.stock"
											:value="initNum(item)" size="small" :modifyFlag="modifyFlag"
											@change="cartNumChange($event, { siteIndex, cartIndex })"
											@limit="goodsLimit($event, cartIndex)" />
									</view>
								</view>
							</view>
							<view class="item-del color-base-bg" :class="{ show: item.edit }"
								@click="deleteCart('single', siteIndex, cartIndex)">{{ $lang('del') }}</view>
						</view>
					</block>
				</view>

				<view class="cart-wrap invalid" v-if="invalidGoods.length">
					<block v-for="(goodsItem, goodsIndex) in invalidGoods" :key="goodsIndex">
						<view class="cart-header mb-40">
							<view class="num-wrap">
								<text class="font-size-base">失效商品</text>
							</view>
							<view class="cart-action font-size-goods-tag iconfont iconicon7" @click="clearInvalidGoods">
							</view>
						</view>
						<view class="cart-goods invalid-goods">
							<view class="goods-wrap">
								<view class="iconfont iconyuan_checkbox color-tip"></view>
								<view class="goods-img ">
									<image :src="$util.img(goodsItem.sku_image, { size: 'mid' })" mode="aspectFill">
									</image>
									<view class="invalid-bg"></view>
									<image class="invalid_img" :src="$util.img('upload/uniapp/cart_invalid.png')">
									</image>
								</view>
								<view class="goods-info">
									<view class="goods-name color-909">{{ goodsItem.sku_name }}</view>
									<view class="goods-sub-section">
										<text class="goods-price color-base-text">
											<view class="color-909 fs-28">
												<text class="unit">{{ $lang('common.currencySymbol') }}</text>
												<template v-if="goodsItem.activity_type == 'seckill'">
													{{ goodsItem.activity_price }}
												</template>
												<template v-else>
													{{ goodsItem.market_price ? goodsItem.market_price : goodsItem.price }}
												</template>
											</view>
											<view class="color-909 fs-26">
												<text class="unit">{{ $lang('common.currencySymbol') }}</text>
												<text>{{goodsItem.price}}</text>
											</view>
										</text>
										<uni-number-box :disabled="true"
											:min="goodsItem.min_buy > 1 ? goodsItem.min_buy : 1"
											:max="goodsItem.max_buy > 0 && goodsItem.max_buy < goodsItem.stock ? goodsItem.max_buy : goodsItem.stock"
											:value="initNum(goodsItem)" size="small" :modifyFlag="modifyFlag"
											@change="cartNumChange($event, { siteIndex, cartIndex })"
											@limit="goodsLimit($event, cartIndex)" />
									</view>
								</view>
							</view>
						</view>
					</block>
				</view>
			</block>
			<block v-else>
				<view class="cart-empty">
					<image :src="$util.img('upload/uniapp/common-empty.png')" mode="aspectFit"></image>
					<view class="color-tip margin-top margin-bottom">{{ $lang('emptyTips') }}</view>
					<button type="primary" size="mini" class="button" v-if="tokenStore"
						@click="$util.redirectTo('/pages/index/index/index', {}, 'reLaunch')">去逛逛</button>
					<button type="primary" size="mini" class="button" v-if="!tokenStore" @click="toLogin">去登录</button>
				</view>
			</block>
		</scroll-view>
		<nsGoodsRecommend ref="goodrecommend" @getCartData="getCartData" @calculationTotalPrice="calculationTotalPrice">
		</nsGoodsRecommend>
		<view class="cart-bottom" v-if="hasData">
			<view class="all-election" @click="allElection">
				<view class="iconfont" :class="checkAll ? 'iconyuan_checked color-import' : 'iconyuan_checkbox'"></view>
				<text>{{ $lang('allElection') }}</text>
			</view>
			<view class="settlement-info" :style="{ visibility: isAction ? 'hidden' : 'visible' }">
				{{ $lang('total') }}:
				<text class="color-price-text font-size-toolbar"><text
						class="pr-20">{{ $lang('common.currencySymbol') }}</text> <text
						class="price-text-40">{{ totalPrice.split('.')[0] }}</text>
					.{{ totalPrice.split('.')[1] }}</text>
			</view>
			<view class="action-btn" v-if="isAction">
				<button type="default" size="mini" @click="deleteCart('all')" plain
					class="delete color-base-bg">{{ $lang('del') }}</button>
			</view>
			<view class="action-btn" v-else>
				<button class="color-text-white color-base-bg" type="default" size="mini" @click="settlement"
					v-if="totalCount != 0">{{ $lang('settlement') }}({{ totalCount }})</button>
				<button type="default" class="color-base-bg" size="mini" @click="settlement" disabled
					v-else>{{ $lang('settlement') }}({{ totalCount }})</button>
			</view>
		</view>
		<!-- 加载动画 -->
		<loading-cover ref="loadingCover"></loading-cover>
		<!-- 底部tabBar -->
		<view class="tabBar-fill"></view>
		<diy-bottom-nav type="shop" :class="{ hide: bottomNavHidden }"></diy-bottom-nav>
		<!-- 返回顶部 -->
		<to-top v-if="showTop" @toTop="scrollToTopNative()"></to-top>

		<ns-login ref="login"></ns-login>
	</view>
</template>

<script>
	import nsGoodsRecommend from '@/components/ns-goods-recommend/ns-goods-recommend.vue';
	import uniNumberBox from '@/components/uni-number-box/uni-number-box.vue';
	import diyBottomNav from '@/components/diy-bottom-nav/diy-bottom-nav.vue';
	import toTop from '@/components/toTop/toTop.vue';
	import scroll from '@/common/js/scroll-view.js';
	import globalConfig from '@/common/js/golbalConfig.js';
	import uniCountDown from '@/components/uni-count-down/uni-count-down.vue';

	export default {
		components: {
			nsGoodsRecommend,
			uniNumberBox,
			diyBottomNav,
			uniCountDown,
			toTop
		},
		mixins: [scroll, globalConfig],
		data() {
			return {
				token: '',
				cartData: [], // 购物车
				checkAll: true,
				totalPrice: '0.00',
				totalCount: 0,
				modifyFlag: false,
				isSub: false,
				invalidGoods: [], // 失效商品集合
				cartBottom: '56px',

				isAction: false, // 是否操作删除
				startX: '', // 触摸开始位置
				endX: '', // 触摸结束位置
				communityConfig: '',
				membercommunity: ''
			};
		},
		onLoad() {
			uni.hideTabBar();
		},
		onShow() {

			// 刷新多语言
			this.$langConfig.refresh();

			if (uni.getStorageSync('token')) {
				this.token = uni.getStorageSync('token')
				this.getCartData();
				this.$store.commit("setTokenStore", this.token);
			} else {
				this.token = '';
				this.cartData = [];
				this.calculationTotalPrice();
				this.$store.commit("setTokenStore", null);
			}

			this.getCommunityConfig();
			this.getMemberCommunity();

			if (this.$refs.goodrecommend) this.$refs.goodrecommend.getCartData();
		},
		onReady() {
			if (!uni.getStorageSync('token')) {
				if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
			}
		},
		computed: {
			hasData() {
				return this.cartData.length > 0 || this.invalidGoods.length > 0;
			},
			tokenStore() {
				this.token = this.$store.state.tokenStore;
				if (this.token) {
					this.getCartData();
				}
				return this.$store.state.tokenStore;
			}
		},
		watch: {
			tokenStore(val, old) {
				this.token = val;
				if (this.token) {
					this.getCartData();
				}
			}
		},
		methods: {
			getMemberCommunity() {
				this.$api.sendRequest({
					url: '/api/community/getMemberCommunity',
					success: res => {
						if (res.code >= 0) {
							this.membercommunity = res.data.community
						}
					}
				});
			},
			getCommunityConfig() {
				this.$api.sendRequest({
					url: '/api/config/community',
					success: res => {
						if (res.code >= 0) {
							this.communityConfig = res.data.pickup_time
						}
					}
				});
			},
			initNum(item) {
				let max_buy = item.max_buy > 0 && item.max_buy < item.stock ? item.max_buy : item.stock;
				max_buy = max_buy == 0 ? 1 : max_buy;
				if (item.num > max_buy) return max_buy;
				return item.num;
			},
			/**
			 * 获取购物车数据
			 */
			getCartData() {
				this.$api.sendRequest({
					url: '/api/cart/goodslists',
					success: res => {
						if (res.code >= 0) {
							// this.token = uni.getStorageSync('token');

							if (res.data.length) {
								this.handleCartData(res.data);
							} else {
								this.cartData = [];
								this.isAction = false;
							}
						} else {
							// this.token = '';
						}
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					},
					fail: res => {
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				});
			},
			/**
			 * 处理购物车数据结构
			 */
			handleCartData(data) {
				this.invalidGoods = [];
				this.cartData = [];
				var temp = {};
				data.forEach((item, index) => {
					if (item.is_invalid == 0) {
						if (item.goods_state == 1) {
							// 如果最小限购超出库存则该商品失效
							if (item.min_buy > 0 && item.min_buy > item.stock) {
								this.invalidGoods.push(item);
							} else {
								item.checked = true;
								item.edit = false;
								if (temp['site_' + item.site_id] != undefined) {
									if (item.activity_type == 'seckill') {

										item.discountTimeMachine = this.$util.countDown(item.surplus_time);

									} else {
										item.discountTimeMachine = null;
									}
									temp['site_' + item.site_id].cartList.push(item);
								} else {
									if (item.activity_type == 'seckill') {

										item.discountTimeMachine = this.$util.countDown(item.surplus_time);

									} else {
										item.discountTimeMachine = null;
									}
									temp['site_' + item.site_id] = {
										siteId: item.site_id,
										siteName: item.site_name,
										edit: false,
										checked: true,
										cartList: [item]
									};
								}
							}
						} else {
							this.invalidGoods.push(item);
						}
					} else {
						this.invalidGoods.push(item);
					}
				});

				this.cartData = [];
				Object.keys(temp).forEach(key => {
					this.cartData.push(temp[key]);
				});
				this.calculationTotalPrice();
				if (this.cartData.length) {
					this.cartData[0].cartList.forEach(v => {
						if (v.sku_spec_format) {
							v.sku_spec_format = JSON.parse(v.sku_spec_format);
						} else {
							v.sku_spec_format = [];
						}
					});
				}
				if (this.invalidGoods.length) {
					this.invalidGoods.forEach(v => {
						if (v.sku_spec_format) {
							v.sku_spec_format = JSON.parse(v.sku_spec_format);
						} else {
							v.sku_spec_format = [];
						}
					});
				}
			},
			/**
			 * 单选
			 * @param {Object} index
			 */
			singleElection(siteIndex, index) {
				this.cartData[siteIndex].cartList[index].checked = !this.cartData[siteIndex].cartList[index].checked;
				this.calculationTotalPrice();
			},
			/**
			 * 店铺全选
			 * @param {Object} checked
			 */
			siteAllElection(checked, index) {
				this.cartData[index].checked = checked;
				this.cartData[index].cartList.forEach(item => {
					item.checked = checked;
				});
				this.calculationTotalPrice();
			},
			/**
			 * 全选
			 */
			allElection(checked) {
				if (typeof checked == 'boolean') {
					this.checkAll = checked;
				} else {
					this.checkAll = !this.checkAll;
				}
				if (this.cartData.length) {
					this.cartData.forEach(siteItem => {
						siteItem.checked = this.checkAll;
						siteItem.cartList.forEach(item => {
							item.checked = this.checkAll;
						});
					});
				}
				this.calculationTotalPrice();
			},
			/**
			 * 计算购物车总价
			 */
			calculationTotalPrice() {
				if (this.cartData.length) {
					let totalPrice = 0,
						totalCount = 0,
						siteAllElectionCount = 0;

					this.cartData.forEach(siteItem => {
						let siteGoodsCount = 0;
						siteItem.cartList.forEach(item => {
							if (item.checked) {
								siteGoodsCount += 1;
								totalCount += parseInt(item.num);
								if (item.activity_price) {
									totalPrice += item.activity_price * item.num;
								} else {
									if (Number(item.discount_price) > 0 && Number(item.discount_price) <
										Number(item.price)) {
										totalPrice += item.discount_price * item.num;
									} else {
										totalPrice += item.discount_price * item.num;
									}
								}

							}
						});
						if (siteItem.cartList.length == siteGoodsCount) {
							siteItem.checked = true;
							siteAllElectionCount += 1;
						} else {
							siteItem.checked = false;
						}
					});
					this.totalPrice = totalPrice.toFixed(2);
					this.totalCount = totalCount;
					this.checkAll = this.cartData.length == siteAllElectionCount;
				} else {
					this.totalPrice = '0.00';
					this.totalCount = 0;
				}
				this.modifyFlag = false;
			},
			/**
			 * 删除购物车
			 * @param {Object} siteIndex
			 * @param {Object} cartIndex
			 */
			deleteCart(tag, siteIndex, cartIndex) {
				var cart_id = [];
				if (tag == 'all') {
					for (let i = 0; i < this.cartData.length; i++) {
						for (let j = 0; j < this.cartData[i].cartList.length; j++) {
							if (this.cartData[i].cartList[j].checked) cart_id.push(this.cartData[i].cartList[j].cart_id);
						}
					}
				} else {
					cart_id.push(this.cartData[siteIndex].cartList[cartIndex].cart_id);
				}
				if (cart_id.length == 0) {
					this.$util.showToast({
						title: '请选择要删除的商品'
					});
					return;
				}

				uni.showModal({
					title: '提示',
					content: '确定要删除这些商品吗？',
					success: res => {
						if (res.confirm) {
							cart_id = cart_id.toString();
							this.calculationTotalPrice();
							this.getCartNumber();
							this.$api.sendRequest({
								url: '/api/cart/delete',
								data: {
									cart_id
								},
								success: res => {
									if (res.code >= 0) {
										this.$store.commit('setGlobalRefresh', '1');
										this.$store.commit('setflRefresh', '1');
										if (this.$refs.goodrecommend) this.$refs.goodrecommend
											.getCartData()
										if (tag == 'all') {
											for (var i = 0; i < this.cartData.length; i++) {
												for (var j = 0; j < this.cartData[i].cartList
													.length; j++) {
													var item = this.cartData[i].cartList[j];
													if (item.checked) {
														this.cartData[i].cartList.splice(j, 1);
														j = -1;
													}
												}
												if (this.cartData[i].cartList.length == 0) this
													.cartData.splice(i, 1);
											}
										} else {
											this.cartData[siteIndex].cartList.splice(cartIndex, 1);
											if (this.cartData[siteIndex].cartList.length == 0) this
												.cartData.splice(siteIndex, 1);
										}
										this.calculationTotalPrice();
										this.getCartNumber();
										if (this.cartData.length > 0) this.isAction = true;
										else this.isAction = false;
									} else {
										this.$util.showToast({
											title: res.message
										});
									}
								}
							});
						}
					}
				});
			},
			/**
			 * 变更购物车数量
			 * @param {Object} params
			 */
			cartNumChange(num, params) {
				if (isNaN(num)) return;
				let data = this.cartData[params.siteIndex].cartList[params.cartIndex],
					max_buy = data.max_buy > 0 && data.max_buy < data.stock ? data.max_buy : data.stock,
					min_buy = data.min_buy > 0 ? data.min_buy : 1;
				if (num > max_buy) num = max_buy;
				if (num < min_buy) num = min_buy;

				this.modifyFlag = true;
				this.$api.sendRequest({
					url: '/api/cart/edit',
					data: {
						num,
						cart_id: this.cartData[params.siteIndex].cartList[params.cartIndex].cart_id
					},
					success: res => {
						if (res.code >= 0) {
							this.cartData[params.siteIndex].cartList[params.cartIndex].num = num;
							this.calculationTotalPrice();
							this.getCartNumber();
							if (!uni.getStorageSync('isRefreshCart')) {
								if (this.$refs.goodrecommend) this.$refs.goodrecommend.getCartData();
							}
						} else {
							this.$util.showToast({
								title: res.message
							});
						}
					}
				});
			},
			/**
			 * 结算
			 */
			settlement() {
				if (this.totalCount > 0) {
					let cart_ids = [];
					this.cartData.forEach(siteItem => {
						siteItem.cartList.forEach(item => {
							if (item.checked) {
								cart_ids.push(item.cart_id);
							}
						});
					});

					if (this.isSub) return;
					this.isSub = true;

					uni.setStorage({
						key: 'orderCreateData',
						data: {
							cart_ids: cart_ids.toString()
						},
						success: () => {
							this.$util.redirectTo('/pages/order/payment/payment');
							this.isSub = false;
						}
					});
				}
			},
			/**
			 * 清空失效商品
			 */
			clearInvalidGoods() {
				uni.showModal({
					title: '提示',
					content: '确定要清空这些商品吗？',
					success: res => {
						if (res.confirm) {
							var cart_ids = [];
							this.invalidGoods.forEach(goodsItem => {
								cart_ids.push(goodsItem.cart_id);
							});
							if (cart_ids.length) {
								this.$api.sendRequest({
									url: '/api/cart/delete',
									data: {
										cart_id: cart_ids.toString()
									},
									success: res => {
										if (res.code >= 0) {
											this.invalidGoods = [];
											this.getCartNumber();
										} else {
											this.$util.showToast({
												title: res.message
											});
										}
									}
								});
							}
						}
					}
				});
			},
			imageError(siteIndex, cartIndex) {
				this.cartData[siteIndex].cartList[cartIndex].sku_image = this.$util.getDefaultImage().default_goods_img;
				this.$forceUpdate();
			},
			toGoodsDetail(item) {
				this.$util.redirectTo('/pages/goods/detail/detail', {
					sku_id: item.sku_id
				});
			},
			// 购物车数量
			getCartNumber() {
				if (uni.getStorageSync('token')) {
					this.$store.dispatch('getCartNumber');
					this.$store.dispatch('getCartPrice');
					this.$store.dispatch('getCartIds');
					this.resetEditStatus();
				}
			},
			goodsLimit(event, index) {
				let data = this.cartData[0].cartList[index];
				if (event.type == 'plus') {
					if (data.max_buy > 0 && data.max_buy < data.stock) {
						this.$util.showToast({
							title: '该商品每人限购' + data.max_buy + '件'
						});
					} else {
						this.$util.showToast({
							title: '库存不足'
						});
					}
				} else {
					this.$util.showToast({
						title: '最少购买' + event.value + '件'
					});
				}
			},
			toLogin() {
				this.$refs.login.open();
			},
			// 手指触摸事件 用于菜单左滑
			touchS(e) {
				this.startX = e.touches[0].clientX;
			},
			touchE(e, cartIndex) {
				this.endX = e.changedTouches[0].clientX;
				// 触摸开始到停止的差值，小于0左滑，大于0右滑
				var disX = this.startX - this.endX;
				// cartIndex.edit = disX > 50;
				if (disX > 50) cartIndex.edit = true;
				else if (disX < 0) cartIndex.edit = false;
				this.$forceUpdate();
			},
			// 重置编辑状态
			resetEditStatus() {
				if (this.cartData[0]) {
					for (var i = 0; i < this.cartData[0].cartList.length; i++) {
						this.cartData[0].cartList[i].edit = false;
					}
				}
				this.$forceUpdate();
			},
			changeAction() {
				this.isAction = !this.isAction;
				this.resetEditStatus();
			}
		}
	};
</script>

<style lang="scss">
	.tab-bar {
		z-index: 899 !important;
	}

	/deep/ .uni-countdown__number {
		height: 28rpx !important;
		line-height: 28rpx !important;
		padding: 0 !important;
		border-radius: 6rpx !important;
	}

	/deep/ .uni-countdown__splitor {
		height: 28rpx !important;
		line-height: 28rpx !important;
	}

	.pr-20 {
		padding-left: 16rpx;
	}

	.color-price-text {
		color: #FF4544;
		font-size: 32rpx !important;
		font-family: PingFang SC;
		font-weight: bold;

		.price-text-40 {
			padding-left: 6rpx;
			margin-right: 0 !important;
			font-size: 40rpx !important;
		}
	}

	.mb-40 {
		margin-bottom: -40rpx !important;
		border-bottom: 1px solid #eee;
	}

	.color-909 {
		color: #909399;
	}

	.invalid-bg {
		top: 40rpx;
		height: 200rpx;
		width: 200rpx;
		position: absolute;
		background-color: rgba(255, 255, 255, 0.5) !important;
	}

	.invalid_img {
		width: 140rpx !important;
		height: 140rpx !important;
		left: 110rpx;
		position: absolute;
		top: 70rpx;
	}

	.fs-26 {
		text-decoration: line-through !important;
		font-size: 16rpx;
	}

	.fs-28 {

		font-size: 28rpx;
	}

	.fs-38 {
		font-size: 38rpx;
	}

	.sextraction {
		font-size: 28rpx;
		font-weight: bold;
		color: #303133;
	}

	.color-import {
		color: #FF6706 !important;
	}

	.color-bg-import {
		background-color: #FF6706 !important;
	}

	.mr-10 {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		margin-right: 14rpx;
		padding-left: 30rpx;
	}

	.sec-kill-shop {
		float: right;
		color: #FF1A0B;
		padding-right: 30rpx;
	}

	.shop-sk-head {
		border-bottom: 1px solid #eee;
		padding: 30rpx 0;
	}

	.allPage {
		height: calc(100vh - 110rpx);
		height: calc(100vh - 110rpx - constant(safe-area-inset-bottom));
		height: calc(100vh - 110rpx - env(safe-area-inset-bottom));
		padding-bottom: 120rpx;
		padding-bottom: calc(120rpx + constant(safe-area-inset-bottom));
		padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
		// overflow-y: auto;

		&.bottom {
			height: calc(100vh - 210rpx);
			height: calc(100vh - 210rpx - constant(safe-area-inset-bottom));
			height: calc(100vh - 210rpx - env(safe-area-inset-bottom));
			padding-bottom: 220rpx;
			padding-bottom: calc(220rpx + constant(safe-area-inset-bottom));
			padding-bottom: calc(220rpx + env(safe-area-inset-bottom));
		}
	}

	.cart-header {
		padding: 20rpx 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		line-height: 40rpx;
		background: #fff;

		&.fixed {
			height: 28px;
			position: absolute;
			width: 100%;
			margin-bottom: 48px;
			z-index: 100;
		}

		.num-wrap {
			margin-left: $margin-both;

			text {
				padding: 0 8rpx;
			}
		}

		.cart-action {
			line-height: inherit;
			margin-right: $margin-both;
		}

		&.invalid {
			margin-left: $margin-both;
			margin-top: $margin-updown;
			flex: 1;
			line-height: inherit;
		}
	}

	.cart-wrap {
		margin-bottom: $margin-updown;

		.fixed-wrap {
			height: 90rpx;
		}

		&.invalid {
			.cart-header {
				margin: 0 $margin-both;
			}
		}

		.cart-goods {
			margin: 40rpx $margin-both 0;
			background: #fff;
			box-sizing: border-box;
			position: relative;

			&:nth-of-type(2) {
				border-top-left-radius: $border-radius;
				border-top-right-radius: $border-radius;
			}

			&:last-child {
				border-bottom-left-radius: $border-radius;
				border-bottom-right-radius: $border-radius;
			}

			.goods-wrap {
				height: 280rpx;
				display: flex;
				position: relative;
				padding-left: 64rpx;
				transition: all 0.1s;

				&>.iconfont {
					font-size: 40rpx;
					position: absolute;
					top: 50%;
					left: 30rpx;
					transform: translateY(-50%);
					transition: all 0.2s;
				}

				&>.iconyuan_checkbox {
					color: $color-disabled;
				}

				&.edit {
					transform: translateX(-70rpx);

					>.iconfont {
						opacity: 0;
					}
				}

				.goods-img {
					width: 200rpx;
					height: 200rpx;
					margin-right: 20rpx;
					border-radius: $border-radius;
					padding-top: 36rpx;
					padding-left: 10rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: $border-radius;
					}
				}

				.goods-info {
					flex: 1;
					position: relative;
					width: calc(100% - 220rpx);
					margin-top: -4rpx;
					padding-top: 36rpx;

					.goods-name {
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: bold;
						width: 400rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						line-height: 1.5;
						height: 46rpx;
						font-size: 30rpx;
					}

					.sku {
						display: flex;
						line-height: 1;
						margin-top: 12rpx;
						height: 46rpx;

						.goods-spec {
							color: #FF6706;
							font-size: 20rpx;
							font-family: PingFang SC;
							font-weight: 500;
							flex: 1;

							text {
								border: 1px solid #FF6706;
								border-radius: 8rpx;
								padding: 6rpx 10rpx;

								&:first-child {
									margin-right: 24rpx;
								}
							}

							// text {
							// 	margin-right: 20rpx;
							// 	&:last-child {
							// 		margin-right: 0;
							// 	}
							// }
						}
					}

					.goods-sub-section {
						height: 120rpx;
						position: absolute;
						left: 0;
						bottom: 20rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;
						width: 100%;

						.unit {
							font-size: $font-size-tag;
							margin-right: 4rpx;
						}

						.goods-notes-text {
							font-size: 26rpx;
							font-family: PingFang SC;
							font-weight: 400;
							height: 32rpx;
							line-height: 24rpx;
							text-decoration: line-through !important;
						}

						.uni-numbox {
							// position: absolute;
							// right: 0;
							top: 10rpx;
							padding-right: 30px;
						}

						.goods-price {
							display: flex;
							flex-direction: row;
							font-weight: bold;

							.bottom-price {
								width: 100%;
								font-size: $font-size-toolbar;
								color: #FF1919;

								image {
									width: 56rpx;
									height: 22rpx;
									margin-left: 6rpx;
								}
							}
						}
					}
				}
			}

			.item-del {
				position: absolute;
				width: 0;
				height: 240rpx;
				color: #fff;
				right: 0;
				bottom: 20rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				transition: all 0.3s;
				overflow: hidden;
				white-space: nowrap;
				font-size: $font-size-tag;

				&.show {
					width: 90rpx;
				}
			}
		}

		.invalid-goods {
			.invalid-mark {
				color: $color-tip;
				padding: 6rpx 16rpx;
				display: inline-block;
				font-size: $font-size-goods-tag;
			}
		}
	}

	.cart-bottom {
		position: fixed;
		z-index: 5;
		width: 100vw;
		height: 100rpx;
		background: #fff;
		bottom: var(--window-bottom);
		bottom: calc(constant(safe-area-inset-bottom) + 56px) !important;
		bottom: calc(env(safe-area-inset-bottom) + 56px) !important;
		overflow: hidden;
		display: flex;
		bottom: 56px;
		z-index: 9;

		.all-election {
			height: 100rpx;
			position: relative;
			display: inline-block;

			&>.iconfont {
				font-size: 40rpx;
				position: absolute;
				top: 50%;
				left: 30rpx;
				transform: translateY(-50%);
			}

			&>.iconyuan_checkbox {
				color: $color-disabled;
			}

			&>text {
				margin-left: 56rpx;
				line-height: 100rpx;
				padding-left: 30rpx;
			}
		}

		.settlement-info {
			flex: 1;
			text-align: right;
			padding-top: 20rpx;
			padding-right: 20rpx;
			line-height: 60rpx;
			height: 60rpx;
			display: flex;
			align-items: center;
			justify-content: flex-end;

			text {
				font-weight: bold;
			}
		}

		.action-btn {
			border-radius: 0;
			margin: 0;
			display: flex;
			justify-content: center;
			align-items: center;
			margin-right: 20rpx;

			button {
				width: 172rpx;
				height: 70rpx;
				line-height: 70rpx;
				font-size: $font-size-base;
				color: white;
				padding: 0 !important;
				border: none !important;

				&.delete {
					height: 70rpx;
					line-height: 70rpx;
					padding: 0 44rpx;
				}
			}
		}
	}

	.tabBar-fill {
		height: calc(constant(safe-area-inset-bottom) + 75px);
		height: calc(env(safe-area-inset-bottom) + 75px);
	}

	.cart-empty {
		text-align: center;
		padding: 140rpx $padding 80rpx $padding;

		image {
			width: 63%;
			height: 450rpx;
		}

		button {
			min-width: 300rpx;
			margin-top: 100rpx;
			height: 70rpx;
			line-height: 70rpx !important;
			font-size: $font-size-base;
		}
	}

	.hide {
		display: none;
	}
</style>
<style scoped>
	/deep/ .reward-popup .uni-popup__wrapper-box {
		background: none !important;
		max-width: unset !important;
		max-height: unset !important;
	}
</style>